const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const TradingStrategies = sequelize.define('TradingStrategies', {
  id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    autoIncrement: true,
    comment: '策略ID',
  },
  userId: {
    type: DataTypes.BIGINT,
    allowNull: false,
    comment: '用户ID',
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '策略名称',
  },
  description: {
    type: DataTypes.TEXT,
    comment: '策略描述',
  },
  strategyType: {
    type: DataTypes.ENUM,
    allowNull: false,
    comment: '策略类型',
  },
  symbol: {
    type: DataTypes.STRING(20),
    allowNull: false,
    comment: '交易对',
  },
  status: {
    type: DataTypes.ENUM,
    defaultValue: inactive,
    comment: '策略状态',
  },
  config: {
    type: DataTypes.JSON,
    allowNull: false,
    comment: '策略配置',
  },
  riskLevel: {
    type: DataTypes.ENUM,
    defaultValue: medium,
    comment: '风险等级',
  },
  maxPositionSize: {
    type: DataTypes.DECIMAL(20, 8),
    comment: '最大仓位大小',
  },
  stopLossPercentage: {
    type: DataTypes.DECIMAL(5, 2),
    comment: '止损百分比',
  },
  takeProfitPercentage: {
    type: DataTypes.DECIMAL(5, 2),
    comment: '止盈百分比',
  },
  deletedAt: {
    type: DataTypes.DATE,
    comment: '删除时间',
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '创建时间',
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '更新时间',
  }
}, {
  tableName: 'trading_strategies',
  comment: '交易策略表',
  timestamps: true,
  paranoid: true,
  underscored: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  deletedAt: 'deleted_at'
});

module.exports = TradingStrategies;
